
////////////////data////////////////////////
///_xxxx：前端专用数据 xxxx_:后端专用数据
var USERDATA =  
{   
    id:null,
    name:'',
    gold:100000,
    //state:'', // ready playing free(旁观也是free 只是有roomid)   不在线:offLine  玩家状态好像没什么用？
    roomId:1000 //1000表示无房间  旁观和桌上的玩家都需要改这个id
}

var ROOMDATA = {
        id:null,
        deskNum:3,
        bottomBet:10000, //goldlimit = 50*bottomBet
        desksData:{ //有一个玩家（ready或playing）就会塞入一个数据 索引是玩家的name,逻辑上是无序的
        },
        state:'', //playing（玩家加入时 不会改变desksData 只能旁观） free 玩家加入时，如果符合要求会加入desksData 
        countdownSeconds:-1, 
        // _countdownScheduler:null  //这个东西不能写在这里 函数里面会掉到ROOMDATA 就造成递归了 导致 Maximum call stack size exceeded
        cardsPool_:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],
        _desksDataByIdx:[],// 客户端数据
        _currentRound:0,
    }

var deskDataModel = {
                cards:[[],[],[]], //1 尾道 2 中道 3 头道
                newRoundCards:[], 
                userData:{},
                userActionTimes_:0, //记录每局游戏中玩家操作次数 如果游戏结束还是0 则踢出
            }
        
////////////////data end////////////////////////

var localizeRoomData = function(roomData)
{
    
    //
    roomData._desksDataByIdx = []

    var deskNodeIdx = 1
    for(var i in roomData.desksData) 
    {      
        if (i == USERDATA.name)
            roomData._desksDataByIdx[3] = roomData.desksData[i]
        else
        {
            if(roomData.deskNum==2&&deskNodeIdx==2)
            {
                roomData._desksDataByIdx[3] = roomData.desksData[i]
                continue
            }
            roomData._desksDataByIdx[deskNodeIdx] = roomData.desksData[i]
            deskNodeIdx = deskNodeIdx + 1
        }
    }

    //回合数
    for(var i in roomData.desksData) 
    {
        var cards = roomData.desksData[i].cards
        var cardsNum = cards[0].length + cards[1].length + cards[2].length
        // var newCardsNum = roomData.desksData[i].newRoundCards.length

        if (cardsNum==0) 
            roomData._currentRound = 1
        else
            roomData._currentRound = (cardsNum-3)/2 + 1

        break
    }

    return roomData
}